
let callback = []
let pedding = false
function flushCallback() {
  pedding = false
  for(let cb of callback) {
    cb()
  }
  callback = []
}
let timerFunc
// 异步函数降级处理Promise > MutationObserver > setImmediate > setTimeout
if(typeof Promise !== 'undefined') {
  const p = Promise.resolve()
  timerFunc = () => {
    p.then(flushCallback)
  }
}

export function nextTick(cb) {
  callback.push(cb)
  // 做一个节流阀，多次调用nextTick最只调用一次
  if(!pedding) {
    timerFunc()
    pedding = true
  }
}